
// 导入redux中actions标识
import types from '../types'

// 定义初始购物车仓库
const defaultState = {
    userinfo: {
        name: '王凤',
        age: 18
    },
    usernum: 2000
}

// 定义购物车reducer函数
function userReducer(state = defaultState, action) {
    if (action.type == types.c) {
        return {
            ...state,
            userinfo: {
                ...state.userinfo,
                age: state.userinfo.age + action.payload
            }
        }
    }
    if (action.type == types.d) {
        return {
            ...state,
            usernum: state.usernum + 1
        }
    }
    // 如果不修改返回原state
    return state
}

// 导出shopReducer
export default userReducer